<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        $orderId=$_REQUEST['orderId'];
        $goodsId=$_REQUEST['goodsId'];
        $shopId=$_REQUEST['shopId'];
        $goodsScore=$_REQUEST['goodsScore'];
        $niming=$_REQUEST['niming'];
        $text=$_REQUEST['text'];
        $src1=$_REQUEST['src1'];
        $src2=$_REQUEST['src2'];
        $src3=$_REQUEST['src3'];
        $src4=$_REQUEST['src4'];
        $pan=$_REQUEST['pan'];
        $time=date('Y-m-d H:i:s');
		$sql="select * from `".$oto."_share` where `userId`='".$user_id."' and orderId='{$orderId}' and goodsId='{$goodsId}' and shopId='{$shopId}'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$share_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
        $sql="select * from `".$oto."_goods_appraises` where `userId`='".$user_id."' and orderId='{$orderId}' and goodsId='{$goodsId}' and shopId='{$shopId}'";
        $result=$db->query($sql);
        while($row=$result->fetch_assoc()){
            $appraises_info[]=$row;//将取得的所有数据赋值给person_info数组
        }
        if($pan=='putong')
        {
            if($src1=='' || is_null($src1))
            {
                $sql="INSERT INTO ".$oto."_goods_appraises (`userId`,`orderId`,`goodsId`,`shopId`,`content`,`createTime`,`anonymity`,`isShow`,`goodsScore`) VALUES ('$user_id','$orderId','$goodsId','$shopId','$text','$time','$niming','1','$goodsScore')";
                $result=$db->query($sql);
                if($result)
                {
                    $data[0]['pan']=1;
                }
                else
                {
                    $data[0]['pan']=0;
                }
            }
            else
            {
                $sql="INSERT INTO ".$oto."_goods_appraises (`userId`,`orderId`,`goodsId`,`shopId`,`content`,`createTime`,`anonymity`,`isShow`,`goodsScore`) VALUES ('$user_id','$orderId','$goodsId','$shopId','$text','$time','$niming','1','$goodsScore')";
                $result=$db->query($sql);
                $sql="INSERT INTO ".$oto."_share (`userId`,`orderId`,`goodsId`,`shopId`,`star`,`shareTitle`,`shareContent`,`shareImg1`,`shareImg2`,`shareImg3`,`shareImg4`,`shareTime`,`anonymity`,`isShow`) VALUES ('$user_id','$orderId','$goodsId','$shopId','$goodsScore','$text','$text','$src1','$src2','$src3','$src4','$time','$niming','0')";
                $result2=$db->query($sql);
                if($result)
                {
                    $data[0]['pan']=1;
                }
                else
                {
                    $data[0]['pan']=0;
                }
            }
        }
        else if($pan=='zhuijia')
        {
            if(!isset($share_info))
            {
                $star=$appraises_info[0]['goodsScore'];
                $shareTitle=$appraises_info[0]['content'];
                $anonymity=$appraises_info[0]['anonymity'];
                $sql="INSERT INTO ".$oto."_share (`userId`,`orderId`,`goodsId`,`shopId`,`star`,`shareTitle`,`shareContent`,`shareImg1`,`shareImg2`,`shareImg3`,`shareImg4`,`shareTime`,`anonymity`,`isShow`) VALUES ('$user_id','$orderId','$goodsId','$shopId','$star','$shareTitle','$shareTitle','$src1','$src2','$src3','$src4','$time','$anonymity','0')";
                $result=$db->query($sql);
                if($result)
                {
                    $data[0]['pan']=1;
                }
                else
                {
                    $data[0]['pan']=0;
                }
                // $sql="update ".$oto."_order set isAppraises='1' where orderId='{$orderId}'";
                // $result=$db->query($sql);
            }
            else
            {
                $sql="update ".$oto."_share set shareImg1='{$src1}',shareImg2='{$src2}',shareImg3='{$src3}',shareImg4='{$src4}' where userId='{$user_id}' and orderId='{$orderId}' and goodsId='{$goodsId}' and shopId='{$shopId}'";
                $result=$db->query($sql);
                if($result)
                {
                    $data[0]['pan']=1;
                }
                else
                {
                    $data[0]['pan']=0;
                }
                $sql="update ".$oto."_goods_appraises set goodsScore='{$goodsScore}' where orderId='{$orderId}' and goodsId='{$goodsId}' and shopId='{$shopId}' and userId='{$user_id}'";
                $result=$db->query($sql);
            }
        }
		echo json_encode($data);
?>